import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import articleIndex from '@/views/articleView/Index'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: 'dashboard', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'profile', icon: 'user', noCache: true }
      }
    ]
  },
  /* 博客展示页面相关路由 start */
  {
    path: '/index',
    component: articleIndex,
    redirect: '/articleHome',
    hidden: true,
    children: [
      /* 首页路由 */
      {
        path: '/articleHome',
        component: () => import('@/views/articleView/container/AntsContainerMain'),
        hidden: true,
        meta: { title: 'articleHome' }
      },
      /* 分类路由 */
      {
        path: '/articleSort',
        name: 'articleSort',
        component: () => import('@/views/articleView/modules/ArticleSort'),
        hidden: true,
        meta: { title: 'articleSort' }
      },
      // /* 标签路由 */
      // {
      //   path: '/articleLable',
      //   name: 'articleLable',
      //   component: () => import('@/views/articleView/modules/ArticleLable'),
      //   hidden: true,
      //   meta: { title: 'articleLable' }
      // },
      /* 归档路由 */
      {
        path: '/articleArchive',
        name: 'articleArchive',
        component: () => import('@/views/articleView/articleArchive/ArticleArchive'),
        hidden: true,
        meta: { title: 'articleArchive' }
      },
      /* 关于我路由 */
      {
        path: '/articleAboutMe',
        name: 'articleAboutMe',
        component: () => import('@/views/articleView/articleAboutMe/ArticleAboutMe'),
        hidden: true,
        meta: { title: 'articleAboutMe' }
      },
      /* 全局搜索 */
      {
        path: '/globalSearch/:value',
        name: 'globalSearch',
        component: () => import('@/views/articleView/globalSearch/GlobalSearch'),
        hidden: true,
        meta: { title: 'globalSearch' }
      },
      /* 展示文章详情路由 */
      {
        path: '/articleDetails/:id',
        name: 'articleDetails',
        component: () => import('@/views/articleView/articleBody/ArticleBody'),
        hidden: true,
        meta: { title: 'articleDetails' }
      },
      /* 左侧分类栏路由 */
      // {
      //   path: '/articleLeftSort/:id',
      //   name: 'articleLeftSort',
      //   component: () => import('@/views/articleView/modules/ArticleLeftSort'),
      //   hidden: true,
      //   meta: { title: 'articleLeftSort' }
      // },
      // /* 左侧标签栏路由 */
      // {
      //   path: '/articleLeftLable/:id',
      //   name: 'articleLeftLable',
      //   component: () => import('@/views/articleView/modules/ArticleLeftLable'),
      //   hidden: true,
      //   meta: { title: 'articleLeftLable' }
      // },
      /* 分类列表：点击标签的时候根据标签查询 */
      {
        path: '/articleSortList/:id',
        name: 'articleSortList',
        component: () => import('@/views/articleView/container/AntsContainerSort'),
        hidden: true,
        meta: { title: 'articleSortList' }
      },
      /* 分类列表：点击标签的时候根据标签查询 */
      {
        path: '/articleLableList/:id',
        name: 'articleLableList',
        component: () => import('@/views/articleView/container/AntsContainerLable'),
        hidden: true,
        meta: { title: 'articleLableList' }
      },
      /* 点击写文章按钮 */
      {
        path: '/writeArticle/:targetPath/:editorType',
        name: 'writeArticle',
        component: () => import('@/views/article/publish/Publish'),
        hidden: true,
        meta: { title: 'writeArticle' }
      },
      /* 点击写文章按钮 */
      {
        path: '/article/publish',
        name: 'publish',
        component: () => import('@/views/article/publish/Publish'),
        hidden: true,
        meta: { title: 'publish' }
      },
      /* 个人主页 */
      {
        path: '/personalHome/:username',
        name: 'personalHome',
        component: () => import('@/views/articleView/personalHome/PersonalHome'),
        hidden: true,
        meta: { title: 'personalHome' }
      },{
        path: '/douYinTool',
        name: 'douYinTool',
        component: () => import('@/views/articleView/douYinTool/DouYinTool'),
        hidden: true,
        meta: { title: 'personalHome' }
      },
      /* 个人中心 */
      {
        path: '/articlePersonal',
        name: 'articlePersonal',
        component: () => import('@/views/articleView/personalHome/ArticlePersonal'),
        redirect: '/personalData',
        hidden: true,
        children: [
          /* 收藏夹 */
          {
            path: '/myFavorites',
            name: 'myFavorites',
            component: () => import('@/views/articleView/personalHome/MyFavorites'),
            hidden: true,
            meta: { title: 'myFavorites' }
          },
          /* 个人资料 */
          {
            path: '/personalData',
            name: 'personalData',
            component: () => import('@/views/articleView/personalHome/PersonalData'),
            hidden: true,
            meta: { title: 'personalData' }
          }
        ]
      },
      /* 壁 纸 */
      {
        path: '/meiTu',
        name: 'meiTu',
        component: () => import('@/views/articleView/wallpaper/Wallpaper'),
        hidden: true,
        meta: { title: 'meiTu' }
      },
      /* 友链 */
      {
        path: '/friendLinks',
        name: 'friendLinks',
        component: () => import('@/views/articleView/friendLinks/FriendLinks'),
        hidden: true,
        meta: { title: 'friendLinks' }
      },
      /* 留言 */
      {
        path: '/leavingMessage',
        name: 'leavingMessage',
        component: () => import('@/views/articleView/leavingMessage/LeavingMessage'),
        hidden: true,
        meta: { title: 'leavingMessage' }
      },
      /* 压缩 */
      {
        path: '/tools',
        name: 'tools',
        component: () => import('@/views/articleView/tools/index'),
        redirect: '/tools/imgCompress',
        hidden: true,
        children: [
          /* 图片压缩 */
          {
            path: '/tools/imgCompress',
            name: 'imgCompress',
            component: () => import('@/views/articleView/tools/imgCompress/index'),
            hidden: true,
            meta: { title: 'imgCompress' }
          },
          /* 图片改尺寸 */
          {
            path: '/tools/imgResize',
            name: 'imgResize',
            component: () => import('@/views/articleView/tools/imgResize/index'),
            hidden: true,
            meta: { title: 'imgResize' }
          },
          /* cron表达式 */
          {
            path: '/tools/cron',
            name: 'cron',
            component: () => import('@/views/articleView/tools/cron/index'),
            hidden: true,
            meta: { title: 'cron' }
          },
          /* JSON格式化 */
          {
            path: '/tools/json',
            name: 'json',
            component: () => import('@/views/articleView/tools/jsonFormat/index'),
            hidden: true,
            meta: { title: 'json' }
          },
          /* Excel转PDF */
          {
            path: '/tools/excelToPdf',
            name: 'excelToPdf',
            component: () => import('@/views/articleView/tools/excelToPdf/index'),
            hidden: true,
            meta: { title: 'excelToPdf' }
          },
          /* Word转PDF */
          {
            path: '/tools/docToPdf',
            name: 'docToPdf',
            component: () => import('@/views/articleView/tools/docToPdf/index'),
            hidden: true,
            meta: { title: 'docToPdf' }
          },
          /* 随机密码生成器 */
          {
            path: '/tools/randomPassword',
            name: 'randomPassword',
            component: () => import('@/views/articleView/tools/randomPassword/index'),
            hidden: true,
            meta: { title: 'randomPassword' }
          },
        ]
      },

    ]
  },
  /* 文章不存在 */
  {
    path: '/article_404',
    name: 'article_404',
    component: () => import('@/views/articleView/article_404/NotArticle'),
    hidden: true,
    meta: { title: 'article_404' }
  },

  /* 博客展示页面相关路由 end */
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

  // {
  //   path: '/error',
  //   component: Layout,
  //   redirect: 'noRedirect',
  //   name: 'ErrorPages',
  //   meta: {
  //     title: 'errorPages',
  //     icon: '404'
  //   },
  //   children: [
  //     {
  //       path: '401',
  //       component: () => import('@/views/error-page/401'),
  //       name: 'Page401',
  //       meta: { title: 'page401', noCache: true }
  //     },
  //     {
  //       path: '404',
  //       component: () => import('@/views/error-page/404'),
  //       name: 'Page404',
  //       meta: { title: 'page404', noCache: true }
  //     }
  //   ]
  // },

  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://github.com/PanJiaChen/vue-element-admin',
        meta: { title: 'externalLink', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
